package com.cs.pk.form.check;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;

public class PaintListenerAdapter implements PaintListener {

    ICheck condition = null;

    public PaintListenerAdapter(ICheck check) {
	condition = check;
    }

    public void paintControl(PaintEvent e) {
	if (condition.verify(e)) {
	    updateBorder(e.gc, (Color) condition.getPassObject(), condition
		    .getCheckObject());
	} else {
	    updateBorder(e.gc, (Color) condition.getFailObject(), condition
		    .getCheckObject());
	}
    }

    private void updateBorder(GC gc, Color c, Control field) {
	gc.setBackground(c);
	Rectangle rText = field.getBounds();
	Rectangle rect1 = new Rectangle(rText.x - 1, rText.y - 1,
		rText.width + 2, rText.height + 2);
	gc.fillRectangle(rect1);
    }
}